﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using DFYE.Web.Models;
using JULONG.WEB.Library;

namespace DFYE.Web.Areas.manage.Models
{
    using Models;

    public class dbInit
    {
        static DataSession<entityDBContainer, manageUser> db = new DataSession<entityDBContainer, manageUser>();

        public static bool isNewDB
        {
            get
            {
                return !db.query().Any();
            }
        }

        public void start()
        {
            if (!isNewDB) return;
            manageUserInit();
        }

        void manageUserInit()
        {

            userType ut = new userType();
            ut.name = "管理员";
            ut.index = 0;

            manageUser user = new manageUser();
            user.userType = ut;
            user.loginname = "admin";
            user.password = "admin".MD5();
            user.username = "系统管理员";
            user.datetime = DateTime.Now;
            user.requirement = true;
            db.insert(user);


            DataSession<entityDBContainer, documentType> dbdctype = new DataSession<entityDBContainer, documentType>();
            documentType dctype = new documentType();
            dctype.able = true;
            dctype.name = "新闻";
            dctype.requirement = true;
            dbdctype.insert(dctype);
            
            

            dctype = new documentType();
            dctype.able = true;
            dctype.name = "相册";
            dctype.requirement = true;
            dbdctype.insert(dctype);


            return;

            dctype = new documentType();
            dctype.able = true;
            dctype.name = "作业条";
            dbdctype.insert(dctype);

            dctype = new documentType();
            dctype.able = true;
            dctype.name = "班级新闻";
            dbdctype.insert(dctype);

            dctype = new documentType();
            dctype.able = true;
            dctype.name = "光荣榜";
            dbdctype.insert(dctype);   

        }
    }
}